/**
 * 解析时间获得年龄
 * @param nowDate 当前时间
 */
export var parseDateAge = function parseDateAge(args) {
  var nowDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Date();
  var year = args.year,
      month = args.month,
      day = args.day;
  var nowYear = nowDate.getFullYear();
  var nowMonth = nowDate.getMonth() + 1;
  var nowDay = nowDate.getDate();
  var age = nowYear - year - 1;

  if (month < nowMonth || "".concat(month) === "".concat(nowMonth) && day <= nowDay) {
    age += 1;
  }

  return age;
};
/**
 * 解析身份证
 * @param idCard 身份证号码
 * @param nowDate 当前时间
 */

export var parseIDCard = function parseIDCard(idCard) {
  var nowDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Date();
  var year = idCard.substring(6, 10);
  var month = idCard.substring(10, 12);
  var day = idCard.substring(12, 14);
  var birthday = "".concat(year, "-").concat(month, "-").concat(day);
  var sex = window.parseInt(idCard.substr(16, 1), 10) % 2 === 1 ? '1' : '0';
  var age = parseDateAge({
    year: window.parseInt(year, 10),
    month: window.parseInt(month, 10),
    day: window.parseInt(day, 10)
  }, nowDate);
  return {
    birthday: birthday,
    sex: sex,
    age: age,
    year: year,
    month: month,
    day: day
  };
};